﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class ERCOLLET
    {
        public static void _ERCOLLET(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double d1 = 11;
            double d2 = 11.5;
            double d3 = 9.5;
            double d4 = 5;
            double l = 18;
            double l1 = 2.5;
            double l2 = 2;
            double l3 = 3.8;
            double l4 = 7;
            double dh7 = 2.5;


            //坐标
            Vector2 v1 = new Vector2(-l-4-l, 0);
            Vector2 v2 = new Vector2(v1.X + l + 4, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 2, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + d2 / 2 - l1 * Math.Tan(30 * pi / 180));
            Vector2 v5 = new Vector2(v3.X + l1, v3.Y + d2 / 2);
            Vector2 v6 = new Vector2(v5.X, v3.Y + d3 / 2);
            Vector2 v7 = new Vector2(v6.X + l2, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v5.Y);
            Vector2 v30 = new Vector2(v5.X + l3, v3.Y + d1 / 2);
            Vector2 v9 = new Vector2(v3.X + l, v30.Y - (l - l1 - l3) * Math.Tan(8 * pi / 180));
            Vector2 v10 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v31 = new Vector2(v30.X, v30.Y * -1);
            Vector2 v11 = new Vector2(v8.X, v8.Y * -1);
            Vector2 v12 = new Vector2(v7.X, v7.Y * -1);
            Vector2 v13 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v14 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v15 = new Vector2(v4.X, v4.Y * -1);
            Vector2 v16 = new Vector2(v3.X, v3.Y + dh7 / 2 + dh7 / 8.5);
            Vector2 v17 = new Vector2(v3.X + dh7 / 8.5, v3.Y + dh7 / 2);
            Vector2 v18 = new Vector2(v9.X - l4, v17.Y);
            Vector2 v19 = new Vector2(v18.X, v3.Y + d4 / 2 - 1);
            Vector2 v20 = new Vector2(v19.X + 1, v19.Y + 1);
            Vector2 v21 = new Vector2(v9.X, v20.Y);
            Vector2 v22 = new Vector2(v16.X, v16.Y * -1);
            Vector2 v23 = new Vector2(v17.X, v17.Y * -1);
            Vector2 v24 = new Vector2(v18.X, v18.Y * -1);
            Vector2 v25 = new Vector2(v19.X, v19.Y * -1);
            Vector2 v26 = new Vector2(v20.X, v20.Y * -1);
            Vector2 v27 = new Vector2(v21.X, v21.Y * -1);
            Vector2 v28 = new Vector2(v16.X, v16.Y + dh7 / 10.625);
            Vector2 v29 = new Vector2(v18.X, v28.Y);

            Vector2 v32 = new Vector2(v2.X + l, v2.Y);
            Vector2 v33 = new Vector2(v32.X - d2 / 2 - 2, v32.Y);
            Vector2 v34 = new Vector2(v32.X + d2 / 2 + 2, v32.Y);
            Vector2 v35 = new Vector2(v32.X, v32.Y + d2 / 2 + 2);
            Vector2 v36 = new Vector2(v32.X, v32.Y - d2 / 2 - 2);
            Vector2 v37 = fun.Polar(v32, 112.5 * pi / 180, d2 / 2 + 2);
            Vector2 v39 = fun.Polar(v32, 135 * pi / 180, d2 / 2 + 2);
            Vector2 v41 = fun.Polar(v32, 157.5 * pi / 180, d2 / 2 + 2);
            Vector2 v43 = fun.Polar(v32, 67.5 * pi / 180, d2 / 2 + 2);
            Vector2 v45 = fun.Polar(v32, 45 * pi / 180, d2 / 2 + 2);
            Vector2 v47 = fun.Polar(v32, 22.5 * pi / 180, d2 / 2 + 2);
            Vector2 v42 = new Vector2(v47.X, v47.Y * -1);
            Vector2 v40 = new Vector2(v45.X, v45.Y * -1);
            Vector2 v38 = new Vector2(v43.X, v43.Y * -1);
            Vector2 v44 = new Vector2(v37.X, v37.Y * -1);
            Vector2 v46 = new Vector2(v39.X, v39.Y * -1);
            Vector2 v48 = new Vector2(v41.X, v41.Y * -1);
            Vector2 v49 = fun.Polar(v32, 82.5 * pi / 180, dh7 / 2);
            Vector2 v50 = new Vector2(v49.X, v49.Y + d2 / 31);
            Vector2 v51 = new Vector2(v50.X + d2 / 51.907, v50.Y);
            Vector2 v52 = new Vector2(v51.X, v51.Y + d2 / 2.7845);
            Vector2 v53 = fun.Polar(v32, 75 * pi / 180, d2 / 2);
            Vector2 v54 = fun.Polar(v32, 75 * pi / 180, d3 / 2);
            Vector2 v55 = fun.Polar(v32, 60 * pi / 180, d3 / 2);
            Vector2 v56 = fun.Polar(v32, 60 * pi / 180, d2 / 2);
            Vector2 v60 = fun.Polar(v32, 52.5 * pi / 180, dh7 / 2);
            Vector2 v59 = fun.Polar(v60, 45 * pi / 180, d2 / 31);
            Vector2 v58 = fun.Polar(v59, 135 * pi / 180, d2 / 51.907);
            Vector2 v57 = fun.Polar(v58, 45 * pi / 180, d2 / 2.7845);
            Vector2 v61 = new Vector2(v51.X, v32.Y + (v4.Y - v3.Y) / 2.009 * 2);
            Vector2 v62 = fun.Polar(v58, 45 * pi / 180, v61.Y - v51.Y);
            Vector2 v63 = new Vector2(v51.X, v61.Y - d2 / 31.9444);
            Vector2 v64 = new Vector2(v63.X - (v63.X - v32.X) * 2, v63.Y);
            Vector2 v65 = new Vector2(v51.X, v51.Y + d2 / 11.5);
            Vector2 v66 = new Vector2(v65.X - (v65.X - v32.X) * 2, v65.Y);





            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v8));
            line2.Vertexes.Add(new LwPolylineVertex(v30));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v31));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v15));
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v29));
            line3.Vertexes.Add(new LwPolylineVertex(v28));
            line3.Vertexes.Add(new LwPolylineVertex(v16));
            line3.Vertexes.Add(new LwPolylineVertex(v17));
            line3.Vertexes.Add(new LwPolylineVertex(v23));
            line3.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v17));
            line4.Vertexes.Add(new LwPolylineVertex(v18));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            line4.Vertexes.Add(new LwPolylineVertex(v23));
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v21));
            line5.Vertexes.Add(new LwPolylineVertex(v20));
            line5.Vertexes.Add(new LwPolylineVertex(v19));
            line5.Vertexes.Add(new LwPolylineVertex(v25));
            line5.Vertexes.Add(new LwPolylineVertex(v26));
            line5.Vertexes.Add(new LwPolylineVertex(v27));
            line5.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
            line5.Vertexes[3].Bulge = Math.Tan(90 * pi / 180 / 4);
            fun.PolyFill(dxf, line5, 0.1, contour);

            Line line6 = new Line(v35, v36);
            line6.Layer = centre;
            line6.Linetype = Linetype.DashDot;
            line6.LinetypeScale = 3;
            dxf.AddEntity(line6);

            Line line7 = new Line(v37, v38);
            line7.Layer = centre;
            line7.Linetype = Linetype.DashDot;
            line7.LinetypeScale = 3;
            dxf.AddEntity(line7);

            Line line8 = new Line(v39, v40);
            line8.Layer = centre;
            line8.Linetype = Linetype.DashDot;
            line8.LinetypeScale = 3;
            dxf.AddEntity(line8);

            Line line9 = new Line(v41, v42);
            line9.Layer = centre;
            line9.Linetype = Linetype.DashDot;
            line9.LinetypeScale = 3;
            dxf.AddEntity(line9);

            Line line10 = new Line(v33, v34);
            line10.Layer = centre;
            line10.Linetype = Linetype.DashDot;
            line10.LinetypeScale = 3;
            dxf.AddEntity(line10);

            Line line11 = new Line(v43, v44);
            line11.Layer = centre;
            line11.Linetype = Linetype.DashDot;
            line11.LinetypeScale = 3;
            dxf.AddEntity(line11);

            Line line12 = new Line(v45, v46);
            line12.Layer = centre;
            line12.Linetype = Linetype.DashDot;
            line12.LinetypeScale = 3;
            dxf.AddEntity(line12);

            Line line13 = new Line(v47, v48);
            line13.Layer = centre;
            line13.Linetype = Linetype.DashDot;
            line13.LinetypeScale = 3;
            dxf.AddEntity(line13);

            LwPolyline line14 = new LwPolyline();
            line14.Vertexes.Add(new LwPolylineVertex(v49));
            line14.Vertexes.Add(new LwPolylineVertex(v50));
            line14.Vertexes.Add(new LwPolylineVertex(v51));
            line14.Vertexes.Add(new LwPolylineVertex(v52));
            line14.Vertexes.Add(new LwPolylineVertex(v53));
            line14.Vertexes.Add(new LwPolylineVertex(v54));
            line14.Vertexes.Add(new LwPolylineVertex(v55));
            line14.Vertexes.Add(new LwPolylineVertex(v56));
            line14.Vertexes.Add(new LwPolylineVertex(v57));
            line14.Vertexes.Add(new LwPolylineVertex(v58));
            line14.Vertexes.Add(new LwPolylineVertex(v59));
            line14.Vertexes.Add(new LwPolylineVertex(v60));
            line14.Vertexes.Add(new LwPolylineVertex(v49));
            line14.Vertexes[3].Bulge = Math.Tan(-11 * pi / 180 / 4);
            line14.Vertexes[5].Bulge = Math.Tan(-15 * pi / 180 / 4);
            line14.Vertexes[7].Bulge = Math.Tan(-11 * pi / 180 / 4);
            line14.Vertexes[11].Bulge = Math.Tan(30 * pi / 180 / 4);
            fun.PolyFill(dxf, line14, 0.1, contour);

            LwPolyline line15 = new LwPolyline();
            line15.Vertexes.Add(new LwPolylineVertex(v62));
            line15.Vertexes.Add(new LwPolylineVertex(v61));
            line15.Vertexes[0].Bulge = Math.Tan(35 * pi / 180 / 4);
            fun.PolyFill(dxf, line15, 0.1, contour);

            LwPolyline line16 = new LwPolyline();
            line16.Vertexes.Add(new LwPolylineVertex(v64));
            line16.Vertexes.Add(new LwPolylineVertex(v63));
            line16.Vertexes.Add(new LwPolylineVertex(v65));
            line16.Vertexes.Add(new LwPolylineVertex(v66));
            fun.PolyFill(dxf, line16, 0.1, contour);

            LwPolyline[] linepoarray1 = new LwPolyline[100];
            linepoarray1 = fun.arrayrpolyline(line14, 8);
            for (int i = 1; i <= 8; i++)
            {
                fun.PolyFill(dxf, linepoarray1[i], 0.2, contour);
            };

            LwPolyline[] linepoarray2 = new LwPolyline[100];
            linepoarray2 = fun.arrayrpolyline(line15, 8);
            for (int i = 1; i <= 8; i++)
            {
                fun.PolyFill(dxf, linepoarray2[i], 0.2, contour);
            };

            LwPolyline[] linepoarray3 = new LwPolyline[100];
            linepoarray3 = fun.arrayrpolyline(line16, 8);
            for (int i = 1; i <= 8; i++)
            {
                fun.PolyFill(dxf, linepoarray3[i], 0.2, contour);
            };



            //标注

            double height = 2;
            double arrowsize = 1;
            double exline = 2;




            fun.dimrot1(dxf, v5, v14, 90, d2 * 2, 1, height, arrowsize, exline, "d2=" + d2, "", "");

            fun.dimrot1(dxf, v6, v13, 90, d3 * 3 / 2, 1, height, arrowsize, exline, "d3=" + d3, "", "");

            fun.dimrot1(dxf, v17, v23, 90, dh7, 1, height, arrowsize, exline, "dH7=" + dh7, "", "");

            fun.dimrot1(dxf, v4, v5, 0, l1 * 2, 1, height, arrowsize, exline, "L1=" + l1, "", "");

            fun.dimrot1(dxf, v8, v5, 0, l2 * 4, 1, height, arrowsize, exline, "L2=" + l2, "", "");

            fun.dimrot1(dxf, v4, v30, 0, l3 * 4, 1, height, arrowsize, exline, "L3=" + l3, "", "");

            fun.dimrot1(dxf, v31, v30, -90, l3, 1, height, arrowsize, exline, "d1=" + d1, "", "");

            fun.dimrot1(dxf, v21, v27, -90, l3, 1, height, arrowsize, exline, "d4=" + d4, "", "");

            fun.dimrot1(dxf, v25, v27, 180, l4 * 2, 1, height, arrowsize, exline, "L4=" + l4, "", "");

            fun.dimrot1(dxf, v15, v27, 180, d3 * 2, 1, height, arrowsize, exline, "L=" + l, "", "");

            fun.jdbz2(dxf, new Line(v15, fun.Polar(v15, 150 * pi / 180, 0.1)), new Line(v4, fun.Polar(v4, -150 * pi / 180, 0.1)), -5, height, arrowsize, exline, "60°", "", "");

            fun.jdbz2(dxf, new Line(v9, fun.Polar(v9, -8 * pi / 180, 0.1)), new Line(v10, fun.Polar(v10, 8 * pi / 180, 0.1)), - 23, height, arrowsize, exline, "16°", "", "");




            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

}
}

